function goback() {
  location.href = "./index.html";
}
$(".header>img").click(() => goback());
$(".section>img").click(() => goback());
$(".chart>img").click(() => goback());
$(".nav>div")
  .eq(2)
  .siblings()
  .click(() => goback())
  .end()
  .click(function () {
    $("html,body").animate({ scrollTop: 0 }, 500);
  });

document.onreadystatechange = function () {
  if (document.readyState === "interactive") {
    let ul = document.querySelector("ul");
    let el = "";
    fetch("http://chst.vip:1234/api/getmoneyctrl")
      .then((body) => body.json())
      .then((res) => {
        res.result.forEach((item) => {
          let regExp = /(?<=imgurl=)[^'"]*/;
          let url = item.productImg2.match(regExp);
          el += ` <li id=${item.productId}>
        <img src="${url[0]}" alt="">
        <p>
        ${item.productName}
        <span>${item.productPinkage}</span>
        </p>
        <span>${item.productFrom}|${item.productTime}</span>
        <span>${item.productComCount}</span>
    </li>`;
        });
        ul.innerHTML = el;
      });
  }
};

// 请求首页数据
let ul = document.querySelector("ul");
ul.addEventListener(
  "click",
  function (e) {
    const arr = [...e.path].reverse();
    let _this = arr[5];
    let id = _this.getAttribute("id");
    let name = $(_this).find("p").text();
    location.href = "./pages/xq.html?id=" + id + "&name=" + name + "&age=22";
  },
  false
);

// 页面跳转
$(".col").on("click", "div", function () {
  switch ($(this).index(".col>div")) {
    case 0:
      location.href = "./pages/bjss.html";
      break;
    case 1:
      location.href = "./pages/sjk.html";
      break;
    case 2:
      location.href = "./pages/gnzc.html";
      break;
    case 3:
      location.href = "./pages/bcj.html";
      break;
    case 4:
      location.href = "./pages/sjk.html";
      break;
    case 5:
      location.href = "./pages/yhq.html";
      break;
    case 6:
      location.href = "./pages/bjss.html";
      break;
    // case 7:location.href='./pages/sjk.html'
    // break;
    case 8:
      location.href = "./pages/cdp.html";
      break;
    case 9:
      location.href = "./pages/bjss.html";
      break;
    case 10:
      location.href = "./pages/scdh.html";
      break;
    case 11:
      location.href = "./pages/ppdq.html";
      break;
  }
});

// 更多
$(".col>.col-icon")
  .eq(7)
  .click(function () {
    let flag = $(this).prop("flag");
    if (flag) {
      $(".container>.col").eq(2).slideDown(500);
      $(this).prop("flag", false);
      return;
    }
    $(".container>.col").eq(2).slideUp(500);
    $(this).prop("flag", true);
  });
